﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Entities;
using NUnit.Framework;
using DataAccess;
using System.Data.SqlClient;
using Common.Helper;

namespace Test_Mock_Group3.HieuTT5.Iteration_3
{
    [TestFixture]
    public class DataAccessInsertService
    {

        

        #region funtions for set up and tear down

        private Service curentService;
        List<string> serviceId;
        private bool DeleteTest(string serviceId)
        {
            var colParameter = new Collection<SqlParameter>
                                   {
                                       new SqlParameter("ServiceId",serviceId)
                                       
                                      
                                   };
            return SqlHelper.ExecuteNonQuery("ServiceDeleteTest", colParameter) > 0;
        }

        bool InsertTest(Service service)
        {
            var colParameter = new Collection<SqlParameter>
                                   {
                                       new SqlParameter("ServiceId",service.ServiceId),
                                       
                                       new SqlParameter("ServiceName",service.ServiceName),
                                       new SqlParameter("ShortDescription",service.ShortDescription),
                                      
                                       new SqlParameter("DeptCode",service.DeptCode)
                                   };
            return SqlHelper.ExecuteNonQuery("ServiceInsertTest", colParameter) > 0;
        }


        [SetUp]
        public void SetUp()
        {
            serviceId = new List<string>();

            var service1 = new Service
            {
                ServiceId = new Guid("76d3e483-006e-4227-8b13-0722acb65159"),
                ServiceName = "Service 1",
                ShortDescription = "Test_ShortDescription1",
                DeptCode = "11111"
            };
            if (InsertTest(service1))
                serviceId.Add(service1.ServiceId.ToString());
           
            //data for insert
            curentService = new Service();
            curentService.ServiceId = new Guid("76d3e483-006e-4227-8b13-0722acb65160");
            curentService.ServiceName = "Service 2";
            curentService.ShortDescription = "Test_ShortDescription1";
            curentService.DeptCode = "111111111";
            curentService.ContactId = Guid.Empty;
            curentService.SubType = 1;
            curentService.ClientDescription = string.Empty;
            curentService.ServiceAttendance = string.Empty;
            curentService.StartExpected = "sdfa";
            curentService.StartDate = string.Empty;
            curentService.EndDate = string.Empty;
            curentService.Extendable = string.Empty;
            curentService.ServiceActive = false;
            curentService.FullDescription = string.Empty;
            curentService.ServiceType = 1;
            curentService.DescriptionDelivery = string.Empty;
            curentService.StagedPayment = false;
            curentService.ProcessMethod = string.Empty;
            curentService.TimeLimited = string.Empty;
            curentService.BenefitsCriterion = string.Empty;
            curentService.BarriersCriterion = string.Empty;
            curentService.EthnicityCriterion = string.Empty;
            curentService.Disability = string.Empty;
            curentService.PersonalCircumstances = string.Empty;
            curentService.OtherServiceParticiPationCriterion = string.Empty;
            curentService.ClientSupportProcess = string.Empty;
            curentService.ClientOutcome = string.Empty;
            curentService.TargetClient = string.Empty;
            curentService.ReferralSources = string.Empty;
            curentService.SupportCentres = string.Empty;
            curentService.OtherServiceId = string.Empty;
            curentService.ProgrammeId = Guid.Empty;
            curentService.ContractOutcome = string.Empty;
            curentService.ContractObligation = string.Empty;
            curentService.Participation = string.Empty;
            curentService.ContractCode = string.Empty;
            curentService.ContractValue = string.Empty;
            curentService.FundingSource = string.Empty;
            curentService.FundingContactId = Guid.Empty;
            curentService.FundingAmount = 0;
            curentService.FundingStart = string.Empty;
            curentService.FundingEnd = string.Empty;
            curentService.FundingNeeds = 0;
            curentService.FundingContinuationNeeded = false;
            curentService.FundingCoutinuationAmount = 0;
            curentService.FundingContinuationDetails = string.Empty;
            curentService.FundraisingForText = string.Empty;
            curentService.FundraisingWhy = string.Empty;
            curentService.FundraisingNeeds = 0;
            curentService.FundraisingRequiredBy = string.Empty;
            curentService.FundraisingComplete = false;
            curentService.FundraisingCompleteDate = string.Empty;
            curentService.FundraisingDonorAnonym = false;
            curentService.FundraisingDonorAmount = 0;
            curentService.FundraisingDonationDate = string.Empty;
            curentService.FundraisingDonationIncremental = false;
            curentService.ClientJourney = string.Empty;
            curentService.Accreditations = string.Empty;
            curentService.InterventionId = string.Empty;

        }

        [TearDown]
        public void TearDown()
        {
            foreach (string t in serviceId)
                DeleteTest(t);
            serviceId.Clear();

            DeleteTest("76d3e483-006e-4227-8b13-0722acb65160");
        }

        #endregion

        [Test]
        public void TestInsertService_InputServiceNull_ReturnFail()
        {
            var expect = -1;
            var actual = ServiceDataAccess.Instance.InsertService(null);
            Assert.AreEqual(actual, expect);
        }

        [Test]
        public void TestInsertService_InputServiceNameNull_ReturnFail()
        {
            var serviceTest = new Service
            {
                ServiceId = new Guid("76d3e483-006e-4227-8b13-0722acb65159"),
                ServiceName = null,
                ShortDescription = "Test_ShortDescription1",
                DeptCode = "11111"
            };
            var expect = -1;
            var actual = ServiceDataAccess.Instance.InsertService(serviceTest);
            Assert.AreEqual(actual, expect);
        }

        [Test]
        public void TestInsertService_InputShortDescNull_ReturnFail()
        {
            var serviceTest = new Service
            {
                ServiceId = new Guid("76d3e483-006e-4227-8b13-0722acb65159"),
                ServiceName = "Service 1",
                ShortDescription = null,
                DeptCode = "11111"
            };
            var expect = -1;
            var actual = ServiceDataAccess.Instance.InsertService(serviceTest);
            Assert.AreEqual(actual, expect);
        }

        [Test]
        public void TestInsertService_InputDeptCodeNull_ReturnFail()
        {
            var serviceTest = new Service
            {
                ServiceId = new Guid("76d3e483-006e-4227-8b13-0722acb65159"),
                ServiceName = "ServiceTest name",
                ShortDescription = "desc test",
                DeptCode = null
            };
            var expect = -1;
            var actual = ServiceDataAccess.Instance.InsertService(serviceTest);
            Assert.AreEqual(actual, expect);
        }

          [Test]
        public void TestInsertService_InputDuplicateServiceName_ReturnFail()
        {
            var serviceTest = new Service
            {
                ServiceId = new Guid("76d3e483-006e-4227-8b13-0722acb65159"),
                ServiceName = "Service 1",
                ShortDescription = "desc test",
                DeptCode = "aaaa"
            };
            var expect = -1;
            var actual = ServiceDataAccess.Instance.InsertService(serviceTest);
            Assert.AreEqual(actual, expect);
        }

          [Test]
          public void TestInsertService_InputValidService_ReturnSuccess()
          {
              

            
              var expected = 1;
              var actual = ServiceDataAccess.Instance.InsertService(curentService);
              Assert.AreEqual(actual, expected);
          }
     
     
    }
}
